      program trapezio
      intrinsic exp, log, sin
      real linear, nonl
      external linear
      external nonl
      call tint(1.0,5.0,linear,res)
      print *, "Resultado: ",res
      call tint(1.0,5.0,nonl,res)
      print *, "Resultado: ",res
      end

      subroutine tint(a,b,fun,res)
      real a, b,res
      integer*8 n
      real h2, alfa
      real fun
      external fun
      n = 5000000      
Cf2py intent(in) a
Cf2py intent(in) b
Cf2py intent(in) fun
Cf2py intent(out,hide,cache) res     
      h2 = (b-a)/(2*n)
      alfa=h2*fun(a)+h2*fun(b)
      res=0.0
      do i=1,n
         p = a+i*2*h2
         res = res+2*h2*fun(p)
      end do
      res = res+alfa
      return
      end
      
      real function linear(x)
      real x
Cf2py intent(in,out) x
      linear = x+1.0
      return
      end

      real function nonl(x)
      real x
Cf2py intent(in,out) x
      nonl = exp(x**2*log(x+x*sin(x)))
      return
      end
           
	

		
